package cn.wolfcode.service.impl;

import ch.qos.logback.core.net.SyslogOutputStream;
import cn.wolfcode.domain.User;
import cn.wolfcode.repository.UserRepository;
import cn.wolfcode.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;


@Service
public class UserSeiviceImpl implements IUserService{

    @Autowired
    private UserRepository userRepository;

    @Override
    public void save(User user) {
        userRepository.save(user);
    }

    @Override
    public void update(User user) {
        userRepository.save(user);
    }

    @Override
    public void delete(String id) {
        userRepository.deleteById(id);
    }

    @Override
    public List<User> list() {
        List<User> users= userRepository.findAll();
        System.err.println(userRepository.getClass());
        return users;
    }

    @Override
    public User get(String id) {
        Optional<User> qo = userRepository.findById(id);
        if(qo.isPresent()){
            User user = qo.get();
            return qo.get();
        }
        return null;
    }

    @Override
    public List<User> queryByName(String name) {
        return userRepository.findByName(name);
    }
}
